"use strict";
cc._RF.push(module, '2da35x6KthImKlsTLjYrDi5', 'LocalizationBase');
// eazax-ccc/components/localization/LocalizationBase.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultLang = exports.Lang = exports.LANG_CHANGED = void 0;
var EventManager_1 = require("../../core/EventManager");
/** 语言更改事件 */
exports.LANG_CHANGED = 'lang-change';
/** 语言 */
var Lang;
(function (Lang) {
    /** 中文 */
    Lang["Cn"] = "cn";
    /** 英语 */
    Lang["Eng"] = "eng";
})(Lang = exports.Lang || (exports.Lang = {}));
/** 默认语言 */
var DefaultLang;
(function (DefaultLang) {
    /** 中文 */
    DefaultLang[DefaultLang["cn"] = 1] = "cn";
    /** 英语 */
    DefaultLang[DefaultLang["eng"] = 2] = "eng";
})(DefaultLang = exports.DefaultLang || (exports.DefaultLang = {}));
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
/**
 * 多语言组件基类
 * @see LocalizationBase.ts https://gitee.com/ifaswind/eazax-ccc/blob/master/components/localization/LocalizationBase.ts
 */
var LocalizationBase = /** @class */ (function (_super) {
    __extends(LocalizationBase, _super);
    function LocalizationBase() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.defaultLang = DefaultLang.cn;
        _this.curLang = Lang.Cn;
        _this.langChanged = function (lang) {
            _this.curLang = lang;
            _this.onLangChanged(lang);
        };
        return _this;
    }
    LocalizationBase.prototype.onLoad = function () {
        EventManager_1.default.on(exports.LANG_CHANGED, this.langChanged, this);
    };
    LocalizationBase.prototype.onDestroy = function () {
        EventManager_1.default.off(exports.LANG_CHANGED, this.langChanged, this);
    };
    /**
     * 语言更改回调（子类重写该函数以具体实现）
     */
    LocalizationBase.prototype.onLangChanged = function (lang) {
    };
    /**
     * 获取当前语言资源
     */
    LocalizationBase.prototype.get = function () {
        if (this[this.curLang]) {
            if (Array.isArray(this[this.curLang]) && this[this.curLang].length === 0) {
                return this[DefaultLang[this.defaultLang]];
            }
            else {
                return this[this.curLang];
            }
        }
        else {
            return this[DefaultLang[this.defaultLang]];
        }
    };
    __decorate([
        property({ type: cc.Enum(DefaultLang), tooltip: CC_DEV && '无当前语言资源时使用的默认语言' })
    ], LocalizationBase.prototype, "defaultLang", void 0);
    LocalizationBase = __decorate([
        ccclass
    ], LocalizationBase);
    return LocalizationBase;
}(cc.Component));
exports.default = LocalizationBase;

cc._RF.pop();